package com.ferrlo.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ferrlo.model.Admin;
import com.ferrlo.service.IAdminManager;

@Controller
public class AdminRegisterController {
	
	@Resource(name="adminManager")
	private IAdminManager adminManager;

	@RequestMapping(value = "/adminRegister")
	public String adminRegister(HttpServletRequest request) {

		String username = request.getParameter("username");
		String pwd = request.getParameter("pwd");
		
		Admin admin = findAdminByAName(username);
		if (admin != null) {
			System.out.println("==== SUCCESS ====");
		}else {
			System.out.println("==== FAIL ====");
		}

		return "index";
	}
	
	
	
	
	

	private Admin findAdminByAName(String name) {

		String dqQuery = "AdminManager.findAdminByAName.query";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("name", "demo");
		List<Admin> admins = adminManager.findListByDynamicQuery(dqQuery, map);
		if (admins.size() != 0) {
			return admins.get(0);
		}
		
		return null;
	}

}
